<?php
/**
 * communit.as
 * @copyright (C)2008 J. William McCarthy, All Rights Reserved.
 * @category communitas
 * @package communitas
 * @author J. William McCarthy
 * @link http://communit.as communit.as
 * @license http://communit.as/docs/license License
 */

/**
 *
 * @package communitas
 * @subpackage forum_models
 * @license http://communit.as/docs/license License 
 */

class Posts extends App_Db_Table_Abstract
{
    protected $_name 	= 'forum_posts';
    protected $_primary = 'id';

    function insert(array $data){
    	$data['post'] = App_Common::convertlinebreaks($data['post']);
    	$data['created_on'] = date(DB_DATETIME_FORMAT);
    	$data['updated_on'] = date(DB_DATETIME_FORMAT);
    	return parent::insert($data);	
    }

    function update(array $data,$where){
    	$data['post'] = App_Common::convertlinebreaks($data['post']);
    	$data['updated_on'] = date(DB_DATETIME_FORMAT);
    	return parent::update($data,$where);
    }

    function getLatestByTopicId($topic_id, $howmany){
    	return $this->fetchRow('topic_id = ' . $topic_id, 'created_on desc', $howmany);
    }

	function getLatest($howmany){
    	return $this->fetchAll("status = 'active'", 'created_on desc', $howmany);
	}

}
